package com.ruoyi.kong.proxy;

import com.ruoyi.kong.entity.*;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

/**
 * kong 服务信息
 */
public interface IKongClientProxy {

    /******************************************服务开始**************************************************/
    /**
     * 获取kong 的 信息
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET  /")
    Map info();

    /**
     * 获取 com.ruoyi.kong 的状态
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET  /status")
    Map status();

    /**
     * 获取kong 的 所有服务信息
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /services")
    KongEntity<KongServiceResult> services();


    /**
     * 获取kong 的 根据id 返回service
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /services/{serviceId}")
    KongService serviceById(@Param("serviceId") String serviceId);



    /**
     * 获取kong 路由信息 对应的 服务
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /routes/{routeId}/service")
    KongService serviceByRouteId(@Param("routeId") String routeId);


    /**
     * 获取kong 路由信息 对应的 服务
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /plugins/{pluginId}/service")
    KongService serviceByPluginId(@Param("pluginId") String pluginId);


    /**
     * 新增 服务
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /services")
    KongEntity<KongService> addServices(@RequestBody KongService kongService);


    /**
     * 修改服务
     * @param kongService
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("PUT /services/{serviceId}")
    KongEntity<KongService> updateServices(@Param("serviceId") String serviceId,@RequestBody KongService kongService);


    /**
     * 删除服务
     * @param serviceId
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /services/{serviceId}")
    void deleteServices(@Param("serviceId") String serviceId);




    /******************************************服务结束**************************************************/



    /******************************************路由开始**************************************************/

    /**
     *
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /routes")
    KongEntity<KongRoute> routes();


    /**
     *
     * @param routeId
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /routes/{routeId}")
    KongRoute routeById(@Param("routeId")  String routeId);


    /**
     *
     * @param serviceId
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /services/{serviceId}/routes")
    KongEntity<KongRoute> routeByServiceId(@Param("serviceId") String serviceId);


    /**
     *
     * @param pluginId
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /plugins/{pluginId}/route")
    KongRoute routeByPluginId(@Param("pluginId") String pluginId);



    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /routes")
    KongRoute addRoute(@RequestBody KongRoute kongRoute);



    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("PUT /routes/{routeId}")
    KongRoute updateRoute(@Param("routeId") String routeId,@RequestBody KongRouteVo kongRoute);



    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /routes/{routeId}")
    void deleteRoute(@Param("routeId") String routeId);


    /******************************************路由结束**************************************************/


    /******************************************插件开始**************************************************/

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /plugins")
    KongEntity<KongPlugin> plugins();

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /plugins")
    KongEntity<KongPlugin> addPlugin(@RequestBody KongPlugin plugin);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /plugins/{id}")
    KongPlugin pluginById(@Param("id") String id);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /plugins/{id}")
    void deletePlugin(@Param("id") String id);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("PUT /plugins/{id}")
    KongPlugin updatePlugin(@Param("id") String id, @RequestBody KongPluginVo plugin);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /routes/{routeId}/plugins")
    KongEntity<KongPlugin> pluginsByRouteId(@Param("routeId") String routeId);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /services/{serviceId}/plugins")
    KongEntity<KongPlugin> pluginsByServiceId(@Param("serviceId") String serviceId);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /plugins/schema/{name}")
    Map pluginSchemaByName(@Param("name") String name);



    /******************************************上游服务开始**************************************************/
//    private static final String UPSTREAM_URI = "/upstreams";
//    private static final String UPSTREAM_URI_ID = "/upstreams/{id}";


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /upstreams")
    KongEntity<KongUpstream> upstreams();



    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /upstreams/{id}")
    KongUpstream upstreamsById(@Param("id") String id );


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /upstreams")
    KongUpstream addUpstream(@RequestBody KongUpstreamVo kongUpstream);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /upstreams/{upstreamId}")
    KongUpstream updateUpstream(@Param("upstreamId") String upstreamId,@RequestBody KongUpstreamVo kongUpstream);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /upstreams/{upstreamId}")
    void deleteUpstream(@Param("upstreamId") String upstreamId);



    /**
     * 列出与特定上游相关联的目标
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /upstreams/{upstreamId}/health")
    KongEntity<KongTarget> targetsByUpstreamId(@Param("upstreamId") String upstreamId);


    /**
     * 列出上游的所有目标。可能会返回同一目标的多个目标对象，显示特定目标的更改历史记录。最新的目标对象created_at是当前定义。
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /upstreams/{id}/targets/all")
    KongEntity<KongTarget> targetsAllByUpstreamId();

    /**
     * 删除目标   禁用负载均衡器中的目标。在后台 此方法为给定的目标定义创建一个新条目，weight为 0。
     * @param upstreamId
     * @param targetId
     * @return
     */
    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /upstreams/{upstreamId}/targets/{id}")
    KongTarget deleteTarget(@Param("upstreamId") String upstreamId,@Param("id") String targetId);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /upstreams/{upstreamId}/targets")
    KongTarget addTarget(@Param("upstreamId") String upstreamId,@RequestBody KongTarget target);


//    @Headers("Content-Type:application/json;charset=UTF-8")
//    @RequestLine("DELETE /upstreams/{upstreamId}/targets/{id}")
//    KongTarget deleteTarget(@Param("upstreamId") String upstreamId,@Param("upstreamId") String id);

    /******************************************消费者开始**************************************************/

//    private static final String CONSUMER_URI = "/consumers";
//    private static final String CONSUMER_URI_ID = "/consumers/{id}";
//    private static final String CONSUMER_URI_plugins = "/consumers/{customerId}/plugins";
//    private static final String CREDENTIALS_URI = "/consumers/{customerId}/{entityName}";
//    private static final String CREDENTIALS_URI_ID = "/consumers/{customerId}/{entityName}/{entityId}";

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /consumers")
    KongEntity<KongConsumer> consumers();


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /consumers/{id}")
    KongConsumer consumerById(@Param("id") String id);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /consumers")
    KongConsumer addConsumer(@RequestBody KongConsumer consumer);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("PUT /consumers/{id}")
    KongConsumer updateConsumer(@Param("id") String id,@RequestBody KongConsumer consumer);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /consumers/{id}")
    void deleteConsumer(@Param("id") String id);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /consumers/{id}/plugins")
    KongEntity<KongPlugin> consumerPlugins(@Param("id") String id);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /consumers/{id}/{name}")
    KongEntity<Map> consumerCredentialByName(@Param("id") String id,@Param("name") String name);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /consumers/{id}/{name}")
    KongEntity<Map> addConsumerCredential(@Param("id") String id,@Param("name") String name,@RequestBody Map entity);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /consumers/{id}/{name}/{entityId}")
    void deleteConsumerCredential(@Param("id") String id,@Param("name") String name,@Param("entityId" ) String entityId);

    /******************************************证书开始**************************************************/


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /certificates")
    KongEntity<KongCertificate> certificates();


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /certificates/{id}")
    KongCertificate certificateById(@Param("id") String id);



    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /certificates")
    KongCertificate addCertificate(@RequestBody KongCertificate certificate);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /certificates/{id}")
    void deleteCertificate(@Param("id") String id);


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("PUT /certificates/{id}")
    KongCertificate updateCertificate(@Param("id") String id,@RequestBody KongCertificate certificate);





    /******************************************CA证书者开始**************************************************/

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /ca_certificates")
    KongEntity<KongCaCertificate> caCertificates();



    /******************************************SNI开始**************************************************/

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /snis")
    KongEntity<KongSni> snis();


    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("GET /snis/{id}")
    KongSni sniById(@Param("id") String id);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("POST /snis")
    KongSni addSni(@RequestBody KongSni kongSni);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("PUT /snis/{id}")
    KongSni updateSni(@Param("id") String id,@RequestBody KongSni sni);

    @Headers("Content-Type:application/json;charset=UTF-8")
    @RequestLine("DELETE /snis/{id}")
    void deleteSni(@Param("id") String id);









}
